;(function(){
	var $body = $("body");
	function popWrap(){
		//return this;
	};
	popWrap.prototype.topTip= function(object1){
		this.options = $.extend(true, {
			content:"",
			autoClose:false,
			classes:"",
		}, object1);
		$dom = $("<div>",{class:"topTip",text:this.options.content});
		$body.append($dom)
	};
	popWrap.prototype.alert = function(object1){
		var options = $.extend(true, {
			content:"取消成功",
			confirm: new Function,
            init: new Function,
            autoClose:2000
		}, object1);
		var wrap = $('<div>',{"class":"alert_t","id":"alert_t"}),obj = [];
        obj.push('<div class="content">');
        obj.push(options.content)
        obj.push('</div>');
        wrap.prepend(obj.join(''));
		$("body").append(wrap);
		if(typeof options.autoClose ==="number"){
	    	setTimeout(function(){
	    		wrap.fadeOut(300,function(){
	    			wrap.remove();
	    			options.confirm();
	    		});
	    	},options.autoClose);
    	}
	};
	popWrap.prototype.alertRemove = function(){
		$("#alert_t").remove();
		return this;
	};
//	popWrap.prototype.alertClose = function(e){
//		if(e){
//	        var $tips = e.parents("#tips_t");
//			if($tips.size() != 0 ){
//	            $tips.find('.content').removeClass("bounceInDown animated").addClass("bounceOutUp animated");
//				setTimeout(function(){
//	                $tips.fadeOut(500,function(){
//						$(this).remove();
//					});
//				},500);
//			}
//		}else{
//			$("#tips_t").find('.content').removeClass("bounceInDown animated").addClass("bounceOutUp animated");
//				setTimeout(function(){
//	                $("#tips_t").fadeOut(500,function(){
//						$(this).remove();
//					});
//				},500);
//		}
//	};
	
	popWrap.prototype.defult = function(e){
		this.option = $.extend(true, {
			content:"2222",
			title:"pop-title",
			effect:"Letmein",
			close:"X",
			blurbox:".wrap",
			maskClose:true,
			wrap:".wrap",
			btn_l:"取消",
			btn_r:"确定",
			btnNum:2,
			title:"",
			showTitle:true,
			esc: new Function,
			confirm: new Function,
			init:new Function
		}, e);
		var _this = this;
		var obj = {
			$wrap : $("<div>",{"class":"pop-box"}),
			$close : $("<a>",{"class":"pop-close"}).html(this.option.close),
			$mask:$("<div>",{"class":"pop-mask"}),
			$blurbox:$(this.option.wrap)
		};
		var tmp = "<div class='pop_content animate'>\
			<div class='pop-title'></div>\
			<div class='pop-info'></div>\
			<div class='btns'></div>\
		</div>",
		escBtn = $("<a>",{"class":"btn_l","href":"javascript:;","text":"取消"}).on("click",function(e){
			obj.$close.trigger("click");
		});
		confBtn = $("<a>",{"class":"btn_r","href":"javascript:;","text":"确定"}).on("click",function(e){
			obj.$close.trigger("click");
			_this.option.confirm();
		});
		var $tmp = obj.$wrap.append(tmp);
		if(this.option.btnNum == 2){
			$tmp.find(".btns").append(escBtn,confBtn);
		}else if(this.option.btnNum == 1){
			$tmp.find(".btns").append(confBtn).addClass("one");
		};
		$tmp.find(".pop-title").html(_this.option.title).append(obj.$close);
		$tmp.find(".pop-info").html(_this.option.content);
		$tmp.append(obj.$mask);
		$body.append(obj.$wrap);
		
		this.option.init.apply(obj);
		var _effect;
		switch(this.option.effect){ 
			default:
				_effect = "show"
				break;
			case "fadeIn":
				_effect = "fadeIn";
				break;
			case "slideUp":
				_effect = "slideUp";
				break;
			case "fliphorizontal":
				_effect = "fliphorizontal";
				break;
			case "flipvertical":
				_effect = "flipvertical";
				break;
			case "blur":
				_effect = "blur";
				break;
			case "zoomIn":
				_effect = "zoomIn";
				break;
			case "Letmein":
				_effect = "Letmein";
				break;
			case "slipFromTop":
				_effect = "slipFromTop";
				break;
			case "Makeway":
				_effect = "Makeway";
				break;
			case "Newspaper":
				_effect = "Newspaper";
				break;
			case "Fall":
				_effect = "Fall";
				break;
			case "SuperScaled":
				_effect = "SuperScaled";
				break;
		};

		this.effect[_effect].call(obj,this);
		$(document).on("keydown",function(e){
			if(e.keyCode == 27){
				obj.$close.trigger("click");
			}
		});
		if(this.option.maskClose){
			obj.$mask.on("click",function(e){
				obj.$close.trigger("click");
			});	
		}
		return this;
	};
	popWrap.prototype.effect = {                        
		fadeIn:function(){			//jquery
			var _this = this,arg = arguments[0];
			console.log(arguments[0].option.esc)
			this.$wrap.fadeIn(300);
			this.$wrap.find(".pop_content").fadeIn();
			this.$close.on("click",function(){
				_this.$wrap.find(".pop_content").fadeOut();
				_this.$wrap.fadeOut(300,function(){
					_this.$wrap.remove();
				});
				arg.option.esc();
			})
		},
		slideUp:function(){			//jquery
			var _this = this,arg = arguments[0];
			this.$wrap.find(".pop_content").slideDown(300);
			this.$wrap.find(".pop_mask").fadeIn(300);
			this.$close.on("click",function(){
				_this.$wrap.find(".pop_content").slideUp();
				_this.$wrap.find(".pop_mask").fadeOut();
				_this.$wrap.fadeOut(300,function(){
					_this.$wrap.remove();
				});
				arg.option.esc();
			});
		},
		show:function(){			//jquery
			var _this = this,arg = arguments[0];
			this.$wrap.show();
			this.$wrap.find(".pop_content").show();
			this.$close.on("click",function(){
				_this.$wrap.remove();
				arg.option.esc();
			});
		},
		fliphorizontal:function(){		//css3
			var _this = this,arg = arguments[0];
			this.$wrap.fadeIn();
			this.$wrap.find(".pop_content").addClass("fliphorizontal");
			this.$close.on("click",function(){						
				_this.classed = {
					"removeClass":"fliphorizontal",
					"addClass":"fliphorizontal-hide"
				};
				css3AnimateEnd(_this);
				arg.option.esc();
			});
		},
		flipvertical:function(){
			var _this = this,arg = arguments[0];
			this.$wrap.fadeIn();
			this.$wrap.find(".pop_content").addClass("flipvertical");
			this.$close.on("click",function(){
				_this.classed = {
					"removeClass":"flipvertical",
					"addClass":"flipvertical-hide"
				}
				css3AnimateEnd(_this);
				arg.option.esc();
			});
		},
		blur:function(){
		 	var _this = this,arg = arguments[0];
		 	this.$wrap.fadeIn();
		 	this.$wrap.find(".pop_content").addClass("bounceInUp");
		 	this.$blurbox.addClass("blur");
		 	this.$close.on("click",function(){
		 		_this.classed = {
		 			"removeClass":"bounceInUp",
					"addClass":"bounceInUp-hide"
		 		}
		 		css3AnimateEnd(_this);
		 		_this.$blurbox.removeClass("blur");
				arg.option.esc();
		 	});
		},
		zoomIn:function(){
			var _this = this,arg = arguments[0];
		 	this.$wrap.fadeIn();
		 	this.$wrap.find(".pop_content").addClass("zoomIn");
		 	this.$close.on("click",function(){
		 		_this.classed = {
		 			"removeClass":"zoomIn",
					"addClass":"zoomIn-hide"
		 		}
		 		css3AnimateEnd(_this);
				arg.option.esc();
		 	})
		},
		Letmein:function(){
			var _this = this,arg = arguments[0];
		 	this.$wrap.fadeIn();
		 	this.$wrap.find(".pop_content").addClass("bounceInUp");
		 	this.$blurbox.addClass("Letmein");
		 	this.$close.on("click",function(){
		 		_this.classed = {
		 			"removeClass":"bounceInUp",
					"addClass":"bounceInUp-hide"
		 		}
		 		css3AnimateEnd(_this);
		 		_this.$blurbox.removeClass("Letmein");
				arg.option.esc();
		 	});
		},
		slipFromTop:function(){
			var _this = this,arg = arguments[0];
		 	this.$wrap.fadeIn();
		 	this.$wrap.find(".pop_content").addClass("fadeInDownBig");
		 	this.$blurbox.addClass("slipFromTop");
		 	this.$close.on("click",function(){
		 		_this.classed = {
		 			"removeClass":"fadeInDownBig",
					"addClass":"fadeInDownBig-hide"
		 		}
		 		css3AnimateEnd(_this);
		 		_this.$blurbox.removeClass("slipFromTop");
				arg.option.esc();
		 	});
		},
		Makeway:function(){
			var _this = this,arg = arguments[0];
			this.$wrap.fadeIn();
			this.$blurbox.addClass("Makeway");
			this.$wrap.find(".pop_content").addClass("fadeInRight");
			this.$close.on("click",function(){
		 		_this.classed = {
		 			"removeClass":"fadeInRight",
					"addClass":"fadeInDownBig-hide"
		 		}
		 		css3AnimateEnd(_this);
		 		_this.$blurbox.removeClass("Makeway");
				arg.option.esc();
		 	});
		},
		Newspaper:function(){
			var _this = this,arg = arguments[0];
			this.$wrap.fadeIn();
			this.$wrap.find(".pop_content").addClass("Newspaper");
			this.$close.on("click",function(){
				_this.classed = {
		 			"removeClass":"Newspaper",
					"addClass":"Newspaper-hide"
		 		}
				css3AnimateEnd(_this);
				arg.option.esc();
		 	});
		},
		Fall:function(){
			var _this = this,arg = arguments[0];
			this.$wrap.fadeIn();
			this.$wrap.find(".pop_content").addClass("Fall");
			this.$close.on("click",function(){
		 		_this.classed = {
		 			"removeClass":"Fall",
					"addClass":"fadeInDownBig-hide"
		 		}
		 		css3AnimateEnd(_this);
		 		_this.$blurbox.removeClass("Fall");
				arg.option.esc();
		 	});
		},
		SuperScaled:function(){
			var _this = this,arg = arguments[0];
			this.$wrap.fadeIn();
			this.$wrap.find(".pop_content").addClass("SuperScaled");
			this.$close.on("click",function(){
		 		_this.classed = {
		 			"removeClass":"SuperScaled",
					"addClass":"SuperScaled-hide"
		 		}
		 		css3AnimateEnd(_this);
		 		_this.$blurbox.removeClass("SuperScaled");
				arg.option.esc();
		 	});
			
		}
	};
	function css3AnimateEnd(_this){
		_this.$wrap.find(".pop_content").removeClass(_this.classed.removeClass).addClass(_this.classed.addClass).one("webkitAnimationEnd webkitTransitionEnd",function(){
				_this.$wrap.find(".pop_content").fadeOut().removeClass(_this.classed.addClass);
				_this.$wrap.fadeOut(500,function(){
					_this.$wrap.remove();
				});
		});
	}
	window.popF = popWrap; 
})();

